<template>
    <div class="newsinfo-container">
        <h3 class="title">{{ news.title }}</h3>
        <p class="subtitle">
            <span>发表时间：{{ news.add_time | dateFormat }}</span>
            <span>点击：{{ news.click }}</span>
        </p>
        <hr>
        <div class="content" v-html="news.content"></div>

        <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
import axios from 'axios'
import { Toast } from 'mint-ui'
import comment from '../subcomponents/Comment.vue'

export default {
    data () {
        return {
            id : this.$route.params.id,
            news : {}
        }
    },
    created () {
        this.loadNesInfo()
    },
    methods : {
        async loadNesInfo () {
            try {
                const { data } = await axios.get(`/api/news/${this.id}`)
                this.news = data
            } catch (err) {
                const { status, statusText } = err.response
                Toast(status + statusText)
            }
        }
    },
    components : {
        "comment-box" : comment
    }
}
</script>

<style lang="scss" scoped>
.newsinfo-container {
    padding: 0 4px;
    .title {
        font-size: 16px;
        text-align: center;
        margin: 15px 0;
        color: red;
    }
    .subtitle {
        padding: 0 5px;
        font-size: 13px;
        color: #226aff;
        display: flex;
        justify-content: space-between;
    }
    .content {
        img {
            width: 100%;
        }
    }
}
</style>
